#!/usr/bin/perl
#edit_folder.cgi

require './folderman-lib.pl';

&ReadParse();

my $pdir = $in{'locate'};
my $emode = $in{'edit'};
my $folder = $in{'dir'};
if (!(-e $pdir))
{
	&nas_syslog("folderman", "naslog_warning", 30013, "Directory invalid!");
	&error($text{'dir_invalid'});
}
if ($emode=~ /create/)
{
	&header($text{'create_folder_title'}, "", "createfolder", 0, 1);
#	print "<hr>\n";
	print "<form action=save_folder.cgi method=post onsubmit='document.forms[0].savefolder.disabled = true;'>\n";
	print "<input type=hidden name=location value='$pdir'>\n";
	print "<input type=hidden name=edit value='create'>\n";
	print "<table class=group border=1 cellpadding=4 cellspacing=0>\n";
	print "<tr class=title1> <td class=group><b>$text{'create_folder'}</b></td> </tr>\n";
	print "<tr> <td class=group><table class=mode1>\n";
	print "<tr> <td><b>$text{'foldername'}</b></td>\n";
	print "<td><input name=foldername class=text size=30></td> </tr>\n";
	print "<tr> <td><b>$text{'location'}</b></td>\n";
	print "<td><input value='$pdir' class=disabletext disabled=true size=30></td> </tr>\n";
	print "<tr> <td><b>$text{'attribute'}</b></td>\n";
	print "<td><input type=checkbox name=attr value='r' checked>$text{'readable'}</td> </tr>\n";
	print "<tr> <td></td> <td><input type=checkbox name=attr value='w' checked>$text{'writable'}</td> </tr>\n";
	print "<tr> <td></td> <td><input type=checkbox name=attr value='e' checked>$text{'executable'}</td> </tr>\n";
	print "<tr> <td>\n";
	print "<input type=submit name=savefolder value='$text{'submit'}' class=button1></td>\n";
	print "<td align=right><input type=reset value='$text{'reset'}'  class=button1></td> </tr>\n";
	print "</table></td></tr></table></form>\n";
}
if ($emode=~ /property/)
{
	&header($text{'folder_property_title'}, "", "editfolder", 0, 1);
#	print "<hr>\n";
	if ($folder=~ /.+/)
	{
		print "<form action=save_folder.cgi method=post onsubmit='document.forms[0].savefolder.disabled = true;'>\n";
		print "<input type=hidden name=location value='$pdir'>\n";
		print "<input type=hidden name=edit value='property'>\n";
		print "<table class=group border=1 cellpadding=4 cellspacing=0>\n";
		print "<tr class=title1> <td class=group><b>$text{'folder_property'}</b></td> </tr>\n";
		print "<tr> <td class=group><table class=mode1>\n";
		print "<tr> <td><b>$text{'foldername'}</b></td>\n";
		my @st = stat($folder);
		$folder =~ s/^$pdir//;
		print "<td><input name=foldername value='$folder' class=text size=30></td> </tr>\n";
		print "<input type=hidden name=oldname value='$folder'>\n";
		print "<tr> <td><b>$text{'location'}</b></td>\n";
		print "<td><input value='$pdir' class=disabletext disabled=true size=30></td> </tr>\n";
		print "<tr> <td><b>$text{'attribute'}</b></td>\n";
		if ($st[2] & 0004)
		{
			print "<td><input type=checkbox name=attr value='r' checked>$text{'readable'}</td> </tr>\n"
		}
		else
		{
			print "<td><input type=checkbox name=attr value='r'>$text{'readable'}</td> </tr>\n";
		}
		if ($st[2] & 0002)
		{
			print "<tr> <td></td> <td><input type=checkbox name=attr value='w' checked>$text{'writable'}</td> </tr>\n"
		}
		else
		{
			print "<tr> <td></td> <td><input type=checkbox name=attr value='w'>$text{'writable'}</td> </tr>\n";
		}
		if ($st[2] & 0001)
		{
			print "<tr> <td></td> <td><input type=checkbox name=attr value='e' checked>$text{'executable'}</td> </tr>\n"
		}
		else
		{
			print "<tr> <td></td> <td><input type=checkbox name=attr value='e'>$text{'executable'}</td> </tr>\n";
		}
                print "<tr><td><input type=checkbox name=subdir value='s'></td><td>$text{'workonsubdir'}</td></tr>\n";
		print "<tr> <td colspan=2>\n";
		print "<input type=submit name=savefolder value='$text{'submit'}'  class=button1>\n";

		print "</table></td></tr></table></form>\n";
	}
	else
	{
		print "<p>", $text{'noselectfolder'}, "</p>\n";
	}
}


#print "<hr>\n";

&footer("index.cgi?dir=$pdir",  $text{'list_folders_return'});


